package com.lablzh.gdxy.repository.practice;

import com.lablzh.gdxy.entity.practice.Practice;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;


public interface PracticeRepository extends JpaRepository<Practice, Integer>, JpaSpecificationExecutor<Practice> {

    List<Practice> findAllByTeaChooseDdl(LocalDate date);

    @Modifying
    @Transactional
    @Query("update Practice set status=?2 where id=?1")
    int updateStatusById(Integer id, String status);


    List<Practice> findAllByTeacherUsername(String username, Sort sort);

    @Modifying
    @Transactional
    @Query("update Practice set applyed=?2 where id=?1")
    void updateApplyedById(Integer id, int i);


    @Modifying
    @Transactional
    @Query("update Practice set toReview=?2, reviewed=?3 where id=?1")
    void updateToReviewAndReviewedById(Integer id, int i, int i1);


    Practice findByPracticeName(String practiceName);

    @Modifying
    @Transactional
    @Query("update Practice set recv=?2, toSummit=?3, toReview=?4, applyed=?5 where id=?1")
    void updateRecvAndToSummitAndToReviewAndApplyedById(Integer id, int recv, int toSummit, int toReview, int applyed);

    @Modifying
    @Transactional
    @Query("update Practice set recv=?2, toSummit=?3, toReview=?4 where id=?1")
    int updateRecvAndToSummitAndToReviewById(Integer id, int recv, int toSummit, int toReview);



    @Modifying
    @Transactional
    @Query("update  Practice  set toSummit=?2,summited=?3, toReview=?4 where id=?1")
    void updateToSummitAndSummitedAndToReviewById(Integer id, int toSummit, int summited, int toReview);

    @Modifying
    @Transactional
    @Query("update  Practice  set outlineAudit=?2 where id=?1")
    void updateOutlineAuditByID(Integer id, String outlineAudit);

    @Modifying
    @Transactional
    @Query("update  Practice  set outline=?2 where id=?1")
    void updateOutlineByID(Integer id, String filename);


    List<Practice> findAllByCollegeAndGrade(String college, String grade);
}
